package com.action.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;

import com.action.entity.event.SwitchAssetEvent;
import com.action.ui.fragment.RedMapFrament;
import com.action.ui.fragment.PacketFragment;
import com.base.app_core.View.AbstractMainActivity;
import com.base.app_core.service.pressenter.NullPressenter;
import com.base.app_core.util.AppConstants;
import com.hwangjr.rxbus.RxBus;
import com.hwangjr.rxbus.annotation.Subscribe;
import com.hwangjr.rxbus.thread.EventThread;
import com.tbruyelle.rxpermissions2.Permission;
import com.xinglai.yun.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;


public class XYBMainActiviy extends AbstractMainActivity<NullPressenter> {

    @Override
    protected View getWelComeView() {
        return null;
    }

    @Override
    protected void initView() {
        super.initView();
        setSwipeBackEnable(false);
        RxBus.get().register(this);
    }

    @Subscribe(thread = EventThread.MAIN_THREAD)
    public void consumeSwitchAssetEvent(SwitchAssetEvent switchAssetEvent) {
        try {
            tabHost.setCurrentTab(switchAssetEvent.getIndex());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void initData() {
        super.initData();
    }

    @Override
    protected void doGrantedPermission(Permission permission) {
        super.doGrantedPermission(permission);
    }

    protected String[] getPermissions() {
        return AppConstants.appPermission;
    }

    @Override
    public void onWelcomeFinish() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }


    @Override
    protected List<Class<?>> getFragmentList() {
        List fragments = new ArrayList();
        fragments.add(RedMapFrament.class);
        fragments.add(PacketFragment.class);
        return fragments;
    }

    @Override
    protected List<Integer> getFragmentIconList() {
        List icons = new ArrayList();
        icons.add(R.drawable.main_tab_home);
        icons.add(R.drawable.main_tab_mem);
        return icons;
    }


    @Override
    protected List<String> getFragmentTitleList() {
        List titles = new ArrayList();
        titles.add("附近红包");
        titles.add("我的钱包");
        return titles;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            Intent i = new Intent(Intent.ACTION_MAIN);  //主启动，不期望接收数据
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);       //新的activity栈中开启，或者已经存在就调到栈前
            i.addCategory(Intent.CATEGORY_HOME);            //添加种类，为设备首次启动显示的页面
            startActivity(i);
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        RxBus.get().unregister(this);
    }
}
